package cn.itcast.bos.delivery.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.jaxb.PageAdapter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.delivery.dao.PromotionDao;
import cn.itcast.bos.delivery.service.PromotionService;
import cn.itcast.bos.domain.delivery.Promotion;
import cn.itcast.bos.domain.utils.PageBean;

@Service
@Transactional(readOnly=false)
public class PromotionServiceImpl implements PromotionService{
	
	@Autowired
	private PromotionDao promotiondao;
	@Override
	public void save(Promotion t) {
		promotiondao.save(t);
	}
	@Override
	public Page<Promotion> showPromotion(Pageable pageable) {
		// TODO Auto-generated method stub
		Page<Promotion> findAll = promotiondao.findAll(pageable);
		return findAll;
	}
	@Override
	public PageBean<Promotion> getPromotion(int rows, int page) {
		// TODO Auto-generated method stub
		
		Pageable pageable=new PageRequest(page-1, rows);
		Page<Promotion> findAll = promotiondao.findAll(pageable);
		PageBean<Promotion> pagebean=new PageBean<Promotion>();
		pagebean.setTotal(findAll.getTotalElements());
		pagebean.setContent(findAll.getContent());
		return pagebean;
	}
	@Override
	public Promotion getById(int id) {
		// TODO Auto-generated method stub
		Promotion findOne = promotiondao.findOne(id);
		return findOne;
	}
	@Override
	public void deadJob(Date date) {
		// TODO Auto-generated method stub
		promotiondao.deadJob(date);
	}
	@Override
	public PageBean<Promotion> loadPromotion() {
		// TODO Auto-generated method stub
		List<Promotion> promotions = promotiondao.findByStatus("1");
		PageBean<Promotion> page=new PageBean<Promotion>();
		page.setContent(promotions);
		return page;
	}

}
